package cn.laixueit.service;

import cn.laixueit.Client.UserClient;
import cn.laixueit.entity.UserInfo;
import cn.laixueit.pojo.user.User;
import cn.laixueit.properties.JwtProperties;
import cn.laixueit.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthService {

    @Autowired
    private UserClient userClient;

    @Autowired
    private JwtProperties prop;


    public String login(String username, String password) {

        try {
            User user = userClient.query(username, password).getBody();
            if(user == null){
                return null;
            }
            String tokeng = JwtUtils.generateToken(new UserInfo(user.getId(),user.getUsername()),prop.getPrivateKey(),prop.getExpire());
            return tokeng;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
